home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1998 January / PC Answers Issue 49 Cover CD January 1998.iso / Apps / Director / DATA.Z / Lists Lingo.dir / Scripts_3_Main List Handlers.ls < prev    next >
Encoding:
Text File  |  1997-05-10  |  5.8 KB  |  194 lines

  1. on initVars
  2.   global gDefaultLinearList, gDefaultPropList, aVariableName, aVar1, aVar2
  3.   set aVariableName to "apple"
  4.   set aVar1 to 100
  5.   set aVar2 to 200
  6.   set gDefaultLinearList to ["this", "that", "the other thing", aVariableName, 123.40000000000000568, "more text"]
  7.   set gDefaultPropList to [#propertyNameA: 1, #c: 5, #b: "applesauce", "a string": "another string"]
  8. end
  9.  
  10. on buildList pCandidateList, pTypeOfList
  11.   global gDefaultLinearList, gDefaultPropList
  12.   set vValidList to 0
  13.   cursor(4)
  14.   set vValidList to checkList(pCandidateList, pTypeOfList)
  15.   if vValidList = 1 then
  16.     case pTypeOfList of
  17.       #linearList:
  18.         set vNewList to value(the text of member "Building Input Field")
  19.         set gDefaultLinearList to vNewList
  20.         set the text of member "Building Display Field 1" to string(gDefaultLinearList)
  21.       #propList:
  22.         set vNewList to value(the text of member "Building Input Field")
  23.         set gDefaultPropList to vNewList
  24.         set the text of member "Building Display Field 1" to string(gDefaultPropList)
  25.     end case
  26.   end if
  27.   cursor(-1)
  28. end
  29.  
  30. on checkList pCandidateList, pTypeOfList
  31.   set vValidList to 0
  32.   case 1 of
  33.     ilk(value(pCandidateList), pTypeOfList):
  34.       set vValidList to 1
  35.     (listp(value(pCandidateList)) and not ilk(value(pCandidateList), pTypeOfList)):
  36.       displayError("<valid list wrong type>")
  37.     (char 1 of stripSpaces(pCandidateList) <> "["):
  38.       displayError("< when building Lists: Illegal Brackets>")
  39.     (the last char in stripSpaces(pCandidateList) <> "]"):
  40.       displayError("< when building Lists: Illegal Brackets>")
  41.     checkBadList(pCandidateList, pTypeOfList):
  42.     otherwise:
  43.       displayError("<undefined error>")
  44.   end case
  45.   return vValidList
  46. end
  47.  
  48. on checkBadList pCandidateList, pTypeOfList
  49.   set vFoundError to 0
  50.   set pCandidateList to stripSpaces(pCandidateList)
  51.   delete char 1 of pCandidateList
  52.   delete char -30000 of pCandidateList
  53.   set vLastItemNumber to the number of items in pCandidateList
  54.   repeat with m = 1 to vLastItemNumber
  55.     set vCurrentItem to item m of pCandidateList
  56.     case pTypeOfList of
  57.       #linearList:
  58.         if checkItem(vCurrentItem) then
  59.           set vFoundError to 0
  60.         else
  61.           set vFoundError to 1
  62.         end if
  63.       #propList:
  64.         if vCurrentItem contains ":" then
  65.           set the itemDelimiter to ":"
  66.           set vItem1 to item 1 of vCurrentItem
  67.           set vItem2 to item 2 of vCurrentItem
  68.           set the itemDelimiter to ","
  69.           if checkItem(vItem1) and checkItem(vItem2) then
  70.             set vFoundError to 0
  71.           else
  72.             set vFoundError to 1
  73.           end if
  74.         else
  75.           set vValidList to 0
  76.         end if
  77.     end case
  78.     if vFoundError = 1 then
  79.       exit repeat
  80.     end if
  81.   end repeat
  82.   return vFoundError
  83. end
  84.  
  85. on checkItem vCurrentItem
  86.   set vValidItem to 0
  87.   set vCurrentItem to stripSpaces(vCurrentItem)
  88.   case 1 of
  89.     ((vCurrentItem starts QUOTE) and (the last char in vCurrentItem = QUOTE)):
  90.       set vValidItem to 1
  91.     (vCurrentItem = EMPTY):
  92.       set vValidItem to 0
  93.     (vCurrentItem contains " "):
  94.       set vValidItem to 0
  95.     (vCurrentItem contains ":"):
  96.       set vValidItem to 0
  97.     (vCurrentItem contains RETURN):
  98.       set vValidItem to 0
  99.     (vCurrentItem contains "["):
  100.       set vValidItem to 0
  101.     (vCurrentItem contains "]"):
  102.       set vValidItem to 0
  103.     otherwise:
  104.       set vValidItem to 1
  105.   end case
  106.   if vValidItem = 0 then
  107.     displayError("<bad item>")
  108.   end if
  109.   return vValidItem
  110. end
  111.  
  112. on checkPosition whichNumber, whatListLength
  113.   set whichNumber to stripSpaces(whichNumber)
  114.   case 1 of
  115.     voidp(value(whichNumber)):
  116.       displayError("< Illegal values of getAt position>")
  117.       set whichNumber to EMPTY
  118.     (not integerp(value(whichNumber))):
  119.       displayError("<For bad numbers>")
  120.       set whichNumber to EMPTY
  121.     (value(whichNumber) < 1):
  122.       displayError("<Greater than zero>")
  123.       set whichNumber to EMPTY
  124.     (whatListLength = EMPTY):
  125.       set whichNumber to value(whichNumber)
  126.     (value(whichNumber) > whatListLength):
  127.       displayError("<Index Out of Range>")
  128.       set whichNumber to EMPTY
  129.     otherwise:
  130.       set whichNumber to value(whichNumber)
  131.   end case
  132.   return whichNumber
  133. end
  134.  
  135. on checkValue whichValue
  136.   set whichValue to stripSpaces(whichValue)
  137.   case 1 of
  138.     ((char 1 of whichValue = QUOTE) and (the last char in whichValue = QUOTE)):
  139.       set whichValue to stripQuotes(whichValue)
  140.     voidp(value(whichValue)):
  141.       displayError("<no quotes>")
  142.       set whichValue to EMPTY
  143.     (not voidp(value(whichValue))):
  144.       case 1 of
  145.         symbolp(value(whichValue)):
  146.           case 1 of
  147.             (whichValue contains ":"):
  148.               displayError("<symbols no colons>")
  149.               set whichValue to EMPTY
  150.             (whichValue contains " "):
  151.               displayError("<symbols no spaces>")
  152.               set whichValue to EMPTY
  153.             otherwise:
  154.               set whichValue to value(whichValue)
  155.           end case
  156.         integerp(value(whichValue)):
  157.           set whichValue to value(whichValue)
  158.         floatp(value(whichValue)):
  159.           set whichValue to value(whichValue)
  160.       end case
  161.     otherwise:
  162.       set whichValue to EMPTY
  163.   end case
  164.   return whichValue
  165. end
  166.  
  167. on stripSpaces pTextString
  168.   if stringp(pTextString) then
  169.     set vItemSize to the number of chars in pTextString
  170.     repeat with r = 1 to vItemSize
  171.       if char 1 of pTextString = " " then
  172.         delete char 1 of pTextString
  173.       end if
  174.     end repeat
  175.     set vItemSize to the number of chars in pTextString
  176.     repeat with r = 1 to vItemSize
  177.       if the last char in pTextString = " " then
  178.         delete char -30000 of pTextString
  179.       end if
  180.     end repeat
  181.   end if
  182.   return pTextString
  183. end
  184.  
  185. on stripQuotes whichString
  186.   if char 1 of whichString = QUOTE then
  187.     delete char 1 of whichString
  188.   end if
  189.   if the last char in whichString = QUOTE then
  190.     delete char -30000 of whichString
  191.   end if
  192.   return whichString
  193. end
  194.